<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="row">
                <table class="layui-hide"  id="main-table" lay-filter="main-table"></table>
            </div>
        </div>
    </div>
</div>

<script th:inline="none"></script>
<script>
    let paperId = (`[[${paperId}]]`);
    layui.use(['table','form','element'], function(){
        var table = layui.table,
            form = layui.form;
        table.render({
            elem: '#main-table'
            ,height: 650
            ,url: 'question/getPageList'
            ,title: '试卷列表'
            ,where:{paperId:paperId}
            ,page: true
            ,limit:20
            ,toolbar: '#toolbar'
            ,cols: [
                [
                    {type: 'checkbox'}
                    ,{field: 'pianName', title: "题干",width:320,templet:function(d){
                        return "<a class='colum-link' href='javascript:void(0)' onclick='edit(\""+d.id+"\",\"" + d.pianName + "\" , this)'>详情 </a>" + d.text2;
                    }}
                    ,{field: 'questionTypeTxt',title: "题型",width: 80}
                    ,{field: 'pianName', title: "篇",width:180}
                    ,{field: 'chapterName', title: "章",width:180}
                    ,{field: 'jieName', title: "节",width:250}
                    ,{field: 'createTime', title: "登记时间",width:170}

                ]
            ]
            ,done:function(){
                enableRowClick(table,form,'main-table',"main-table");
            }
        });
        //头工具栏事件
        table.on('toolbar(main-table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'replace':
                    var data2 = checkStatus.data;
                    if(data2.length>0){
                        top.layer.open({
                            id:"openwin2",
                            type: 2,
                            title:'替换试题',
                            area:['1700px','800px'],
                            content:  "rooter?url=ksxt/paper/question-list-forreplace&paperId="+data2[0].id,
                            btn:['替换','关闭'],
                            yes:function (index,layero){
                                var iframeWin = top[layero.find('iframe')[0]['name']];
                                let ids = iframeWin.getIds();
                                if(ids.length===0){
                                    top.layer.msg("请选择替换的题目");
                                    return false;
                                }
                                axios.post("question/updateLibQuestionId",{id:data2[0].id,libQuestionId:ids[0].id}).then(res=>{
                                    top.layer.msg("替换成功");
                                    table.reload("main-table");
                                    top.layer.close(index);
                                })
                            }
                        });
                    }else{
                        top.layer.msg("请选择操作数据！")
                    }
                    break;
            };
        });
        var $ = layui.$, active = {
            query: function(){

                table.reload("main-table",{where:{name:$("#name").val()}})
            },
            resetBtn:function () {
                $("#btReset").click();

            }
        };
        window.loadGrid = function(tableName){
            table.reload(tableName);
        }
        $('.layui-form .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
    function edit(questionid){
        top.layer.open({
            id:"editwin",
            type: 2,
            title:'修改题目',
            area:['1500px','880px'],
            content:  'rooter?url=ksxt/paper/add-question1&id='+questionid+"&delFlag=1",
            btn:['关闭']
        });
    }
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="replace"><i class="layui-icon layui-icon-edit"></i>替换</button>
    </div>
</script>
</body>
</html>